﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarehouseWebAPP.code.DAL;
using WarehouseWebAPP.code.DAL.SupplierDSTableAdapters;

namespace WarehouseWebAPP.code.BLL
{
    public class SupplierBLL
    {
        private supplierTableAdapter SupplierAdapter = null;
        public supplierTableAdapter Adapter
        {
            get
            {
                if (SupplierAdapter == null) SupplierAdapter = new supplierTableAdapter();
                return SupplierAdapter;
            }
        }

        public void SupplierInsert(string supplier_name, string supplier_address, string supplier_phone, string supplier_email,
            string supplier_contact_person, string supplier_contact_phone)
        {
            if (supplier_name == null)
                throw new Exception("Supplier Name is missing");
            if (Adapter.SupplierInsert(supplier_name, supplier_address, supplier_phone, supplier_email, supplier_contact_person, supplier_contact_phone) < 1)
                throw new Exception("Supplier was not Added");
        }

        public void SupplierDelete(Guid supplier_num)
        {
            if (supplier_num == null)
                throw new Exception("Supplier Number is missing");
            if (Adapter.SupplierDelete(supplier_num) < 1)
                throw new Exception("Supplier was not deleted");
        }

        public void SupplierUpdate (string supplier_name, string supplier_address, string supplier_phone, string supplier_email,
            string supplier_contact_person, string supplier_contact_phone, Guid supplier_num)
        {
             if (supplier_num == null)
                throw new Exception("Supplier Number is missing");
             if (supplier_name == null)
                throw new Exception("Supplier Name is missing");
             if (Adapter.SupplierUpdate(supplier_name, supplier_address, supplier_phone, supplier_email,
                    supplier_contact_person, supplier_contact_phone, supplier_num)<1)
                throw new Exception("Supplier was not updated");
        }

         public bool SupplierExists(string supplier_name)
         {
             if (supplier_name == null)
                throw new Exception("Supplier Name is missing");
             if  (Adapter.SupplierExists(supplier_name)!=null) return true;
             return false;
         }

         public SupplierDS.supplierDataTable SupplierGetByContact(string contactPerson)
         {
             if (contactPerson == null)
                 throw new Exception("Contact Person Name is missing");
             return Adapter.SupplierGetByContact(contactPerson);
         }

         public SupplierDS.supplierDataTable SupplierGetByName(string supplier_name)
         {
             if (supplier_name == null)
                 throw new Exception("Supplier Name is missing");
             return Adapter.SupplierGetByName(supplier_name);
         }

         public SupplierDS.supplierDataTable SupplierGetByNum(Guid supplier_num)
         {
             return Adapter.SupplierGetByNum(supplier_num);
         }

         public SupplierDS.supplierDataTable SupplierGet()
         {
             return Adapter.GetData();
         }
    }
}
